package com.ruoyi.wretchant.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wretchant.domain.MetaShares;
import com.ruoyi.wretchant.service.IMetaSharesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 股票Controller
 * 
 * @author 简简单单 Online zuozuo
 * @date 2021-08-15
 */
@Controller
@RequestMapping("/wretchant/shares")
public class MetaSharesController extends BaseController
{
    private String prefix = "wretchant/shares";

    @Autowired
    private IMetaSharesService metaSharesService;

    @RequiresPermissions("wretchant:shares:view")
    @GetMapping()
    public String shares()
    {
        return prefix + "/shares";
    }

    /**
     * 查询股票列表
     */
    @RequiresPermissions("wretchant:shares:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MetaShares metaShares)
    {
        startPage();
        List<MetaShares> list = metaSharesService.selectMetaSharesList(metaShares);
        return getDataTable(list);
    }

    /**
     * 导出股票列表
     */
    @RequiresPermissions("wretchant:shares:export")
    @Log(title = "股票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MetaShares metaShares)
    {
        List<MetaShares> list = metaSharesService.selectMetaSharesList(metaShares);
        ExcelUtil<MetaShares> util = new ExcelUtil<MetaShares>(MetaShares.class);
        return util.exportExcel(list, "股票数据");
    }

    /**
     * 新增股票
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存股票
     */
    @RequiresPermissions("wretchant:shares:add")
    @Log(title = "股票", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MetaShares metaShares)
    {
        return toAjax(metaSharesService.insertMetaShares(metaShares));
    }

    /**
     * 修改股票
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MetaShares metaShares = metaSharesService.selectMetaSharesById(id);
        mmap.put("metaShares", metaShares);
        return prefix + "/edit";
    }

    /**
     * 修改保存股票
     */
    @RequiresPermissions("wretchant:shares:edit")
    @Log(title = "股票", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MetaShares metaShares)
    {
        return toAjax(metaSharesService.updateMetaShares(metaShares));
    }

    /**
     * 删除股票
     */
    @RequiresPermissions("wretchant:shares:remove")
    @Log(title = "股票", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(metaSharesService.deleteMetaSharesByIds(ids));
    }
}
